//
//  MyActivitySelected.swift
//  甜言蜜语
//
//  Created by yingli_yanfa_liuxingyu on 16/9/13.
//  Copyright © 2016年 wl. All rights reserved.
//

import UIKit
protocol MyActivitySelectedDeleagte {
    func applyBtnClicked(type: String)
}
class MyActivitySelected: UIView {
    var delegate: MyActivitySelectedDeleagte?
    @IBOutlet weak var applying: UIButton!
    @IBOutlet weak var applySuccess: UIButton!
    @IBOutlet weak var applyError: UIButton!
    @IBOutlet weak var all: UIButton!
    @IBOutlet var customView: UIView!
    var type: String?{
        didSet{
            self.drawingView()
        }
    }
    var maxHeight: CGFloat = 0
    func drawingView() {
        if type == "1"{
            self.all.backgroundColor = UIColor.colorWithRGB(160 , g: 158, b: 157 )
        }
        if type == "2"{
            self.applying.backgroundColor = UIColor.colorWithRGB(160 , g: 158 , b: 157 )
        }
        if type == "3"{
            self.applySuccess.backgroundColor = UIColor.colorWithRGB(160 , g: 158 , b: 157 )
        }
        if type == "4"{
            self.applyError.backgroundColor = UIColor .colorWithRGB(160 , g: 158 , b: 157 )
        }
        
    }
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        self.commonInit()
    }
    
    required init?(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)
        self.commonInit()
    }
    
    
    func commonInit () {
        NSBundle.mainBundle().loadNibNamed("MyActivitySelected", owner: self, options: nil)
        self.customView.frame.size.width = 111
        self.customView.width(self.width)
        self.customView.height(148)
       // self.customView.bottom(self.bottom())
        self.customView.top(0)
        self.customView.frame.origin.x = SCREEN_WIDTH - 111
        self.backgroundColor = UIColor.clearColor()
        self.alpha = 0
        
        
        let maskView:UIView = UIView.init(frame: self.bounds)
        maskView.backgroundColor = UIColor.blackColor()
        maskView.alpha = 0.5
        self.addSubview(maskView)
        
        self.addSubview(self.customView)
        let tap = UITapGestureRecognizer.init(target: self, action:#selector(Sign.tapClick(_:)))
        maskView.addGestureRecognizer(tap)
        self.viewFrame()
        
    }
    
    func tapClick (sender:UITapGestureRecognizer) {
        self.closeBtnClick()
    }
    
    //MARK:view的位置
    func viewFrame() {
        
        if maxHeight == kScreen_height {
            UIView.animateWithDuration(0.25, animations: { () -> Void in
                self.customView.frame.origin.y = kScreen_height
                self.alpha = 0
            })
        } else {
            UIView.animateWithDuration(0.25, animations: { () -> Void in
                self.alpha = 1
                self.customView.top(0)
            })
        }
    }
    
    
    func closeBtnClick(){
        maxHeight = kScreen_height
        self.viewFrame()
        
    }

    @IBAction func applying(sender: UIButton){
        delegate?.applyBtnClicked("2")
        self.closeBtnClick()
    }
    
    @IBAction func applySuccess(sender: UIButton){
        delegate?.applyBtnClicked("3")
         self.closeBtnClick()

    }
    
    @IBAction func applyError(sender: UIButton){
        delegate?.applyBtnClicked("4")
         self.closeBtnClick()

    }
    
    @IBAction func all(sender: UIButton){
        delegate?.applyBtnClicked("1")
         self.closeBtnClick()

    }

}
